<h3>Listagem de dados - <?php echo $this->table['alias']; ?></h3>
<a href="<?php echo $this->basePath; ?>/cms/new/t/<?php echo $this->table['name']; ?>" title="">Novo</a>
<?php if((bool) $this->tableData->getAdapter()->count()) { ?>
	<form action="<?php echo $this->url(); ?>" method="post">
		<div style="text-align: right;">
			<input type="submit" value="Buscar" />
			<input type="submit" value="Limpar Filtros" name="clear" />
		</div>
		<div style="overflow: scroll;">
			<table>
				<thead>
					<tr>
						<th></th>
						<?php foreach($this->fields as $name => $params) { ?>
							<?php if($name == 'ID') { ?>
								<?php foreach($params as $column => $param) { ?>
									<th style="text-align: left;">
										<?php if($param['type'] != 'defaultFilter') { ?>
											<?php if($param['type'] == 'boolean') { ?>
												<input type="radio" class="<?php echo $param['type']; ?>" id="<?php echo $column; ?>_1" name="search[<?php echo $column; ?>]" value="true"<?php if(isset($this->filters[$column]) && $this->filters[$column] == 'true') echo ' checked="checked"'?> />
												<label for="<?php echo $column; ?>_1">Sim</label>
												<input type="radio" class="<?php echo $param['type']; ?>" id="<?php echo $column; ?>_0" name="search[<?php echo $column; ?>]" value="false"<?php if(isset($this->filters[$column]) && $this->filters[$column] == 'false') echo ' checked="checked"'?> />
												<label for="<?php echo $column; ?>_0">Não</label>
											<?php } else { ?>
												<input type="text" class="<?php echo $param['type']; ?>" name="search[<?php echo $column; ?>]" value="<?php if(isset($this->filters[$column])) echo $this->filters[$column]; ?>" />
											<?php } ?>
										<?php } ?>
									</th>
								<?php } ?>
							<?php } else { ?>
								<th style="text-align: left;">
									<?php if($params['type'] !== 'defaultFilter') { ?>
										<?php if($params['type'] == 'boolean') { ?>
											<input type="radio" class="<?php echo $params['type']; ?>" id="<?php echo $name; ?>_1" name="search[<?php echo $name; ?>]" value="true"<?php if(isset($this->filters[$name]) && $this->filters[$name] == 'true') echo ' checked="checked"'?> />
											<label for="<?php echo $name; ?>_1">Sim</label>
											<input type="radio" class="<?php echo $params['type']; ?>" id="<?php echo $name; ?>_0" name="search[<?php echo $name; ?>]" value="false"<?php if(isset($this->filters[$name]) && $this->filters[$name] == 'false') echo ' checked="checked"'?> />
											<label for="<?php echo $name; ?>_0">Não</label>
										<?php } else { ?>
											<input type="text" class="<?php echo $params['type']; ?>" name="search[<?php echo $name; ?>]" value="<?php if(isset($this->filters[$name])) echo $this->filters[$name]; ?>" />
										<?php } ?>
									<?php } ?>
								</th>
							<?php } ?>
						<?php } ?>
					</tr>
					<tr>
						<th>Ações</th>
						<?php foreach($this->fields as $name => $params) { ?>
							<?php if($name == 'ID') { ?>
								<?php foreach($params as $column => $param) { ?>
									<th>ID</th>
								<?php } ?>
							<?php } else { ?>
								<th>
									<a href="<?php echo $this->url(array('o' => $name, 'd' => isset($this->order[$name]) ? $this->order[$name] : 'ASC')); ?>" class="<?php echo isset($this->order[$name]) ? strtolower($this->order[$name]) : 'asc'; ?>"><?php echo $params['name']; ?></a>
								</th>
							<?php } ?>
						<?php } ?>
					</tr>
				</thead>
				<tbody>
					<?php foreach($this->tableData as $chave => $data) { ?>
						<tr id="data_<?php echo $chave; ?>">
							<td>
								<a class="exibir" href="<?php echo $this->basePath; ?>/cms/detail/t/<?php echo $this->ids[$chave]['table']; ?>/c/<?php echo $this->ids[$chave]['column']; ?>/v/<?php echo $this->ids[$chave]['value']; ?>">Exibir</a>
								<a class="excluir" href="<?php echo $this->basePath; ?>/cms/delete/t/<?php echo $this->ids[$chave]['table']; ?>/c/<?php echo $this->ids[$chave]['column']; ?>/v/<?php echo $this->ids[$chave]['value']; ?>">Excluir</a>
								<a class="editar" href="<?php echo $this->basePath; ?>/cms/edit/t/<?php echo $this->ids[$chave]['table']; ?>/c/<?php echo $this->ids[$chave]['column']; ?>/v/<?php echo $this->ids[$chave]['value']; ?>">Editar</a>
							</td>
							<?php foreach($data as $row) { ?>
								<td>
									<?php if(is_array($row)) { ?>
										<?php if(isset($row['repCol'])) { ?>
											<!-- Foreign keys -->
											<a href="<?php echo $this->basePath; ?>/cms/detail/t/<?php echo $row['table']; ?>/c/<?php echo key($row['ref']); ?>/v/<?php echo current($row['ref']); ?>" target="_blank"><?php echo $row['repCol']; ?></a>
										<?php } else { ?>
											<!-- NM DATA -->
											<?php if(!empty($row)) { ?>
												<ul>
													<?php foreach($row as $nm) { ?>
														<li>
															<a href="<?php echo $this->basePath; ?>/cms/detail/t/<?php echo $nm['table']; ?>/c/<?php echo key($nm['ref']); ?>/v/<?php echo current($nm['ref']); ?>" title="Exibir este registro" target="_blank"><?php echo $nm['repCol']; ?></a>
														</li>
													<?php } ?>
												</ul>
											<?php } else { ?>
												<span class="center">- -</span>
											<?php } ?>
										<?php } ?>
									<?php } elseif(is_bool($row)) { ?>
										<?php echo ($row == true) ? 'Sim' : 'Não'; ?>
									<?php } else { ?>
										<?php echo $row; ?>
									<?php }?>
								</td>
							<?php } ?>
						</tr>
					<?php } ?>
				</tbody>
			</table>
		</div>
	</form>
	<?php echo $this->paginationControl($this->tableData, 'Sliding', '/cms/paginator.phtml'); ?>
<?php } else { ?>
	<div class="no-data">Nenhum registro encontrado</div>
<?php } ?>